package com.vitabuybuy.tv.ui.mine.wallet

import android.os.Bundle
import android.view.View
import androidx.lifecycle.Observer
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityMywalletBinding
import com.library.common.base.BaseActivity
import com.library.common.ext.setOnclickNoRepeat
import com.vitabuybuy.tv.ui.mine.wallet.viewmodel.MyWalletViewModel
import com.vitabuybuy.tv.utils.StringUtil
import kotlinx.android.synthetic.main.activity_mywallet.*

class MyWalletActivity : BaseActivity<MyWalletViewModel, ActivityMywalletBinding>(){

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>) {
            mContext.startActivity(null, MyWalletActivity::class.java)
        }
    }

    override val isUseBaseTitleBar: Boolean
        get() = false
    override val layoutId: Int
        get() = R.layout.activity_mywallet

    override fun initView(savedInstanceState: Bundle?) {
        mBinding.mViewModel = viewModel
    }

    override fun onResume() {
        super.onResume()
        viewModel.getMyWallet()
    }

    override fun observeData() {
        viewModel.myWallet.observe(this, Observer {
            tvBalance.text = StringUtil.to2Double(it).toString()
        })
    }

    override fun eventHandling() {
        setOnclickNoRepeat(iv_back, btnWithDraw, rlBill, rlBankCard){v->
            when (v) {
                iv_back -> finish()
                btnWithDraw -> {
                    viewModel.myWallet.value?.run {
                        WithdrawActivity.openActivity(
                            mContext,
                            this
                        )
                    }
                }
                rlBill -> BillActivity.openActivity(mContext)
                rlBankCard -> ChooseAccountActivity.openActivity(mContext, 0x12)
            }

        }
    }
}
